package com.itkjb.leisurely.center.sys.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.itkjb.leisurely.center.sys.mapper.SysUserDepMapper;
import com.itkjb.leisurely.center.sys.model.SysUserDepModel;
import com.itkjb.leisurely.center.sys.service.ISysUserDepService;
import com.itkjb.leisurely.core.base.service.impl.BaseServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 用户组织关系对象，组织成员 服务实现类
 * </p>
 *
 * @author itkjb.com
 * @since 2020-07-17
 */
@Service
public class SysUserDepServiceImpl extends BaseServiceImpl<SysUserDepMapper, SysUserDepModel> implements ISysUserDepService {


    @Override
    public List<SysUserDepModel> findUserDepsByUserId(String userId) {
        return this.baseMapper.findUserDepsByUserId(userId);
    }

    /**
     * wrapper 组装器，构造条件查询
     * @author itkjb.com
     * @date  2020-07-17
     * @param wrapper
     * @param model 条件
     **/
    @Override
    protected void assembleWrapper(QueryWrapper<SysUserDepModel> wrapper, SysUserDepModel model) {
        // （代码生成器生成）自动生成了，list查询的时候，条件组装，开发者自行删除不需要的条件
        // 用户id
        wrapper.lambda().eq(StringUtils.isNotBlank(model.getUserId()), SysUserDepModel::getUserId, model.getUserId() );
        // 组织id
        wrapper.lambda().eq(StringUtils.isNotBlank(model.getDepId()), SysUserDepModel::getDepId, model.getDepId() );
    }

    /**
     * wrapper 组装器，组装list查询时，查询的列
     * @author itkjb.com
     * @date  2020-07-17
     * @param wrapper
     * @param model
     * @return void
     * @since 2020-07-17
     **/
    @Override
    protected void buildListSelectColumns(QueryWrapper<SysUserDepModel> wrapper, SysUserDepModel model){
        buildCommonSelectColumns(wrapper, model);
    }

    /**
     * 组装列表查询的列（字段）
     * @date  2020-07-17
     * @param wrapper
     * @param model
     */
    protected void buildCommonSelectColumns(QueryWrapper<SysUserDepModel> wrapper, SysUserDepModel model){
        // 代码生成器生成，为了简化开发时，查询list时，查询指定字段，没必要查询所有参数
        wrapper.lambda().select(
            // id
            SysUserDepModel::getId,
            // 用户id
            SysUserDepModel::getUserId,
            // 组织id
            SysUserDepModel::getDepId,
            SysUserDepModel::getCreateTime
        );
    }


}
